package com.tran.app.screen

import android.text.TextUtils
import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.wrapContentSize
import androidx.compose.foundation.lazy.LazyColumn
import androidx.compose.foundation.lazy.items
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.ArrowBack
import androidx.compose.material3.Button
import androidx.compose.material3.ExperimentalMaterial3Api
import androidx.compose.material3.HorizontalDivider
import androidx.compose.material3.Icon
import androidx.compose.material3.IconButton
import androidx.compose.material3.Scaffold
import androidx.compose.material3.Text
import androidx.compose.material3.TextButton
import androidx.compose.material3.TextField
import androidx.compose.material3.TopAppBar
import androidx.compose.runtime.Composable
import androidx.compose.runtime.collectAsState
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.setValue
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.drawBehind
import androidx.compose.ui.geometry.Offset
import androidx.compose.ui.graphics.BlendMode.Companion.Color
import androidx.compose.ui.graphics.drawscope.Stroke
import androidx.compose.ui.unit.dp
import androidx.lifecycle.viewmodel.compose.viewModel
import androidx.navigation.NavHostController
import androidx.room.Query
import com.orhanobut.logger.Logger
import com.tran.app.viewmodel.DropCourseScreenVM
import com.tran.app.viewmodel.SCViewModel


@OptIn(ExperimentalMaterial3Api::class)
@Composable
fun DropCourseScreen(padding: Modifier, navCotroller: NavHostController) {
    Scaffold(modifier = Modifier.fillMaxSize(),topBar = {
        TopAppBar(title = { Text(text = "选课")},
            navigationIcon = {
                IconButton(onClick = { navCotroller.popBackStack() }) {
                    Icon(imageVector = Icons.Default.ArrowBack, contentDescription = "back")
                }
            })
    }) {padding->
        val vm:DropCourseScreenVM = DropCourseScreenVM()
        val uistate by vm.uidata.collectAsState()
        LazyColumn(modifier = Modifier
            .padding(padding)
            .fillMaxSize()) {
            items(uistate){
                Column(modifier = Modifier
                    .padding(start = 10.dp, end = 10.dp)
                    .fillMaxWidth()
                    .drawBehind {
                        drawRect(
                            color = androidx.compose.ui.graphics.Color.Black, // 选择你需要的颜色
                            topLeft = Offset.Zero,
                            size = this.size,
                            style = Stroke(width = 1.dp.toPx())
                        )
                    }
                    .clickable {

                    }
                    .padding(top = 10.dp, bottom = 10.dp, start = 10.dp), horizontalAlignment = Alignment.Start) {
                    Text(text = "课程名:"+it.name)
                    Text(text = "考察方式:"+it.exam)
                    Text(text = "学分:"+it.credits)
                    Text(text = "学时:"+it.studyhour)
                    Text(text = "老师:"+it.techname)
                    TextButton(onClick = {
                        vm.unbindCourse(it)
                    }) {
                        Text(text = "解除选课")
                    }
                }
            }
        }
    }
}